package com.example.douyin.friends;

import androidx.lifecycle.MutableLiveData;

import com.example.lib_base_mvvm.baseMVVM.BaseRepo.BaseRepo;
import com.hyphenate.EMCallBack;
import com.hyphenate.EMValueCallBack;

import java.util.List;

public class FriendsRepo extends BaseRepo {
    public void friends(MutableLiveData<List<String>> success,MutableLiveData<String> fail){
        emClient.contactManager().aysncGetAllContactsFromServer(new EMValueCallBack<List<String>>() {
            @Override
            public void onSuccess(List<String> value) {
                success.postValue(value);
            }

            @Override
            public void onError(int error, String errorMsg) {
                fail.postValue(errorMsg);
            }
        });

    }

    public void addFriend(String username,String reason,MutableLiveData<String> success,MutableLiveData<String> fail){
        emClient.contactManager().aysncAddContact(username, reason, new EMCallBack() {
            @Override
            public void onSuccess() {
                success.postValue("添加成功");
            }

            @Override
            public void onError(int code, String error) {
                fail.postValue("添加失败"+error);
            }
        });
    }
}
